﻿using System;
using System.Collections.Generic;
using System.Text;

namespace ObserverPattern
{
    public abstract class Subject
    {
        // Emailer emailler; //强信赖关系
        // Mobile phoneNumber; //强信赖关系

        private List<IObserverAccount> observers = new List<IObserverAccount>();

        IObserverAccount emailer; // 依赖于接口
        IObserverAccount phoneNumber; // 依赖于接口

        private double _money;
        public Subject(double Money)
        {
            this._money = Money;
        }

        public double Money
        {
            get { return _money; }
        }

        public IObserverAccount Emailer
        {
            get { return emailer; }
            set { this.emailer = value; }
        }
        
        public IObserverAccount PhoneNumber
        {
            get { return phoneNumber; }
            set { this.phoneNumber = value; }
        }

        public void WithDraw()
        { 
            foreach(IObserverAccount ob in observers)
            {
                ob.Update(this);
            }
        }

        public void AddObserver(IObserverAccount observer)
        {
            observers.Add(observer);
        }
        public void RemoveObserver(IObserverAccount observer)
        {
            observers.Remove(observer);
        }

    }
}
